package com.lh.config;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;


@Configuration
@EnableTransactionManagement
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
//@Configuration
//@EnableTransactionManagement
//@MapperScan(basePackages = "com.lh.mapper")
//@AutoConfigureAfter({DataSourceAutoConfiguration.class}) // 确保在自动配置之后加载
public class DynamicDataSourceConfig {




    /**
     * 核心配置 - 使用动态数据源自动配置
     */
//    @Bean
//    @Primary
//    public DataSource dataSource(DynamicDataSourceProperties properties) {
//        return properties.initializeDataSourceBuilder().build();
//    }

    /**
     * 事务管理器配置
     */
    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

}